1823D - Unique Palindromes - CodeForces Solution


constructive algorithms math strings *1900

Please click on ads to support us..

C++ Code:

//#pragma GCC optimize ("O3")

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void solve() {
	int n, k;
	cin >> n >> k;
	vector<int> x(k + 1), c(k + 1);
	for (int i{1}; i <= k; ++i) cin >> x[i];
	for (int i{1}; i <= k; ++i) cin >> c[i];

	vector<char> ans(n);
	char abc{'a'};
	ans[0] = 'a', ans[1] = 'b', ans[2] = 'c';
	x[0] = 3, c[0] = 3;

	for (int i{1}; i <= k; ++i) {
		if (x[i] - x[i - 1] < c[i] - c[i - 1]) return cout << "NO\n", []{}();
		int i2{x[i - 1] + c[i] - c[i - 1]};
		for (int j{x[i - 1]}; j < i2; ++j) ans[j] = 'c' + i;
		for (int j{i2}; j < x[i]; ++j) ans[j] = abc, abc = (abc == 'c' ? 'a' : abc + 1);
	}

	cout << "YES\n";
	for (int i{0}; i < n; ++i) cout << ans[i];
	cout << '\n';
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int t{1};
	cin >> t;
	while (t--) solve();
}


Comments

Submit
0 Comments
More Questions

1715D - 2+ doors
267A - Subtractions
1582A - Luntik and Concerts
560A - Currency System in Geraldion
946A - Partition
1068B - LCM
1692E - Binary Deque
679A - Bear and Prime 100
488A - Giga Tower
14A - Letter
1150A - Stock Arbitraging
1552A - Subsequence Permutation
1131F - Asya And Kittens
1475F - Unusual Matrix
133B - Unary
1547A - Shortest Path with Obstacle
624A - Save Luke
1238A - Prime Subtraction
1107C - Brutality
1391B - Fix You
988B - Substrings Sort
312A - Whose sentence is it
513A - Game
1711E - XOR Triangle
688A - Opponents
20C - Dijkstra
1627D - Not Adding
893B - Beautiful Divisors
864B - Polycarp and Letters
1088A - Ehab and another construction problem